/**
* 
*	PushMenu类
*	作者：邓磊
*	时间：2016年7月4日 16:40:43
*	作用：上传微信菜单
*	域：无
*
*/

package com.eptok.weixin.util;


import org.apache.log4j.Logger;

import net.sf.json.JSONObject;
import yspay.express.bean.menu.Button;
import yspay.express.bean.menu.ClickButton;
import yspay.express.bean.menu.ComplexButton;
import yspay.express.bean.menu.Menu;
import yspay.express.bean.menu.ViewButton;
import yspay.express.store.WxConstant;
import yspay.express.store.WxStore;
import yspay.express.util.CommonUtil;

public class PushMenu2{
	
	private static final Logger log = Logger.getLogger(PushMenu2.class);

/*	private static String appid = "wx67e0267aca26ea04";
	private static String appsecret="9e6ced3cdd65f730d27eedbb7e779a68";*/
	
	public static void pushMenu()
	{
		String domain_local = 	"http://wxtest3.eptok.com";
		String domain_test = 	"http://wxtest2.eptok.com";
		String domain_online =  "http://exp.ysepay.com";
		
		ComplexButton b1 = new ComplexButton();
		b1.setName("开发环境");
		
		ViewButton b1_1 = new ViewButton();
		b1_1.setName("个人端");
		b1_1.setType("view");
		b1_1.setUrl(domain_local+"/express_m/weixin/indexUser.do");
		
		ViewButton b1_2 = new ViewButton();
		b1_2.setName("快递员端");
		b1_2.setType("view");
		b1_2.setUrl(domain_local+"/express_m/weixin/indexKdy.do");
		
		ViewButton b1_3 = new ViewButton();
		b1_3.setName("主页");
		b1_3.setType("view");
		b1_3.setUrl(domain_local+"/express_m/weixin/index.do");
		
		Button[] b1_sub = new Button[3];
		b1_sub[0]=b1_1;
		b1_sub[1]=b1_2;
		b1_sub[2]=b1_3;
		b1.setSub_button(b1_sub);
		//**********************************************//
		ComplexButton b2 = new ComplexButton();
		b2.setName("正式环境");
		
		ViewButton b2_1 = new ViewButton();
		b2_1.setName("个人端");
		b2_1.setType("view");
		b2_1.setUrl(domain_online+"/express_m/weixin/indexUser.do");
		
		ViewButton b2_2 = new ViewButton();
		b2_2.setName("快递员端");
		b2_2.setType("view");
		b2_2.setUrl(domain_online+"/express_m/weixin/indexKdy.do");
		
		ViewButton b2_3 = new ViewButton();
		b2_3.setName("主页");
		b2_3.setType("view");
		b2_3.setUrl(domain_online+"/express_m/weixin/index.do");
		
		Button[] b2_sub = new Button[3];
		b2_sub[0]=b2_1;
		b2_sub[1]=b2_2;
		b2_sub[2]=b2_3;
		b2.setSub_button(b2_sub);
		//**********************************************//
		
		ComplexButton b3 = new ComplexButton();
		b3.setName("测试环境");
		
		ViewButton b3_1 = new ViewButton();
		b3_1.setName("个人端");
		b3_1.setType("view");
		b3_1.setUrl(domain_test+"/express_m/weixin/indexUser.do");
		
		ViewButton b3_2 = new ViewButton();
		b3_2.setName("快递员端");
		b3_2.setType("view");
		b3_2.setUrl(domain_test+"/express_m/weixin/indexKdy.do");
		
		ViewButton b3_3 = new ViewButton();
		b3_3.setName("主页");
		b3_3.setType("view");
		b3_3.setUrl(domain_test+"/express_m/weixin/index.do");
		
		Button[] b3_sub = new Button[3];
		b3_sub[0]=b3_1;
		b3_sub[1]=b3_2;
		b3_sub[2]=b3_3;
		b3.setSub_button(b3_sub);
		//**********************************************//
		Menu menu = new Menu();
		Button[] b = new Button[3];
		b[0] = b1;
		b[1] = b2;
		b[2] = b3;
		menu.setButton(b);
		JSONObject json = JSONObject.fromObject(menu);
		log.info(json.toString());
		String accessToken = WxStore.getAccessToken();
		String url = WxConstant.MENU_CREATE_URL.replace("ACCESS_TOKEN", accessToken);
		JSONObject ret = CommonUtil.httpsRequest(url, CommonUtil.REQ_POST, json.toString());
		log.info("创建菜单结果："+ret.toString());
		System.out.println("创建菜单结果："+ret.toString());
	}

	public static void main(String[] args) {
		pushMenu();
	}
	
	
	
/*	public static String getAccessToken()
	{
		
		String requestUrl = WxConstant.TOKEN_Url.replace("APPID",appid).replace("APPSECRET", appsecret);
		JSONObject jsonObject = CommonUtil.httpsRequest(requestUrl,CommonUtil.REQ_GET,null);
		return jsonObject.getString("access_token");
	}*/
	
}
